# 9-1 餐馆
class Restaurant():
    """描述一家餐馆的信息"""
    def __init__(self, restaurant_name, cuisine_type):
        self.name = restaurant_name
        self.type = cuisine_type
        self.number_served = 0

    def describe_restaurant(self):
        """打印一家餐厅的名称和类型"""
        print("名称:" + self.name)
        print("类型:" + self.type)

    def open_restaurant(self):
        """打印餐厅正在营业的信息"""
        print("\n餐厅正在营业")

    def set_number_served(self, number):
        """设置餐厅的就餐人数"""
        self.number_served = number

    def increment_number_served(self, increment_number):
        """增加餐厅的就餐人数"""
        self.number_served += increment_number
kfc = Restaurant('肯德基', '快餐店')

kfc.describe_restaurant()
kfc.open_restaurant()
print("有" + str(kfc.number_served) +  "人在这里就餐过。" )

kfc.set_number_served(23)
print("有" + str(kfc.number_served) +  "人在这里就餐过。" )

kfc.increment_number_served(3)
print("有" + str(kfc.number_served) +  "人在这里就餐过。" )

# 9-2 三家餐馆
# 9-3 用户
class User():
    """描述用户的信息"""

    def __init__(self, first_name, last_name, age):
        """初始化用户基本信息"""
        self.f_name = first_name
        self.l_name = last_name
        self.age = age
        self.login_attempts = 0 # 记录用户登陆次数

    def describe_user(self):
        """描述用户基本信息"""
        full_name = self.f_name.title() + self.l_name.title()
        user_info = {'name:': full_name, 'age' : self.age}
        print(user_info)

    def greet_user(self):
        """打印个性化欢迎语"""
        print("\nHello, " + self.f_name.title() + " " +
              self.l_name.title() + ".")

    def increment_login_attempts(self):
        """将用户的登陆次数加1"""
        self.login_attempts += 1

    def reset_login_attempts(self):
        """重置用户的登陆次数"""
        self.login_attempts = 0

tom = User('tom', 'smith', 27)

tom.describe_user()
tom.greet_user()

print("该用户已经登录" + str(tom.login_attempts) + "次")
tom.increment_login_attempts()
tom.increment_login_attempts()
print("该用户已经登录" + str(tom.login_attempts) + "次")
tom.reset_login_attempts()
print("该用户已经登录" + str(tom.login_attempts) + "次")
# 9-4 就餐人数
# 9-5 尝试登陆次数
# 9-6 冰淇淋小店
class IceCreamStand(Restaurant):
    def __init__(self, restaurant_name, cuisine_type):
        """初始化冰淇淋小店基本信息"""
        super().__init__(restaurant_name, cuisine_type)
        self.flavors = ['草莓', '香草', '蓝莓', '巧克力']

    def display_flavors(self):
        """显示冰淇淋口味"""
        print(self.flavors)

dq = IceCreamStand('dq', '冰淇淋店')
dq.display_flavors()
# 9-7 管理员
class Privileges():
    """描述权限"""

    def __init__(self):
        self.privileges = ['can add post', 'can delete post', 'can ban user']

    def show_privileges(self):
        """显示权限"""
        print(self.privileges)

class Admin(User):
    """描述管理员用户"""
    def __init__(self, first_name, last_name, age):
        """初始化属性"""
        super().__init__(first_name, last_name, age)
        self.privileges  = Privileges()

howie = Admin('howie', 'hsu', 19)
howie.privileges.show_privileges()

# 9-8 权限
# 9-9 电瓶升级
# 9-13 使用OrderDirect
# 9-14 骰子
from random import randint

class Die():
    """这是一个模拟骰子的类"""
    def __init__(self):
        """初始化骰子，点数默认为6"""
        self.sides = 6

    def roll_die(self):
        """通过随机数模拟掷骰子的过程"""
        self.sides = randint(1, 6)
        print("您掷到了" + str(self.sides))

obj = Die() # 实例化
# 把骰子掷10次
for i in range(0, 10):
    obj.roll_die()